package edu.hawaii.myisern.action;

//import java.util.ArrayList;
import java.util.List;
import edu.hawaii.myisern.collaborations.jaxb.Collaboration;
import edu.hawaii.myisern.model.MyIsernModel;
//import edu.hawaii.myisern.model.User;
import edu.hawaii.myisern.organizations.jaxb.Organization;
import edu.hawaii.myisern.researchers.jaxb.Researcher;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.ForwardResolution;
//import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
//import net.sourceforge.stripes.validation.SimpleError;
//import net.sourceforge.stripes.validation.Validate;
//import net.sourceforge.stripes.validation.ValidationError;

/**
 * Provides a web interface for MyISERN.
 * 
 * @author Jon Lao
 * @author Jared Sunouchi
 * @author Chiao-Fen Zielinski-Liu
 */
public class MyIsernActionBean implements ActionBean {
  /** Required by the ActionBean interface. */
  private ActionBeanContext context;

  /** Our single stack instance manipulated by all webapp users. */
  private MyIsernModel myIsern = MyIsernModel.getInstance();

  /** An error string, always displayed, but invisible if empty. */
  private String errorMessage = "";

  /** The researchers. */
  private List<Researcher> researchers;

  /** The organizations. */
  private List<Organization> organizations;

  /** The collaborations. */
  private List<Collaboration> collaborations;

  /** Sanity check results. */
  private List<String> sanityCheckResults;

  /** List label and type. */
  private String listType;

  /**
   * Returns the context. Required by the interface.
   * 
   * @return the ActionBeanContext.
   */
  public ActionBeanContext getContext() {
    return context;
  }

  /**
   * Sets the context. Required by the interface.
   * 
   * @param context The ActionBeanContext to set.
   */
  public void setContext(ActionBeanContext context) {
    this.context = context;
  }

  /**
   * Returns the error message, which may be empty. Indicates if someone tried to pop an empty
   * stack.
   * 
   * @return The error message.
   */
  public String getErrorMessage() {
    return this.errorMessage;
  }

  /**
   * Returns the appropriate label for the data.
   * 
   * @return The list label.
   */
  public String getListType() {
    return this.listType;
  }

  /**
   * Returns the sanity check results.
   * 
   * @return The sanity check results.
   */
  public List<String> getSanityCheckResults() {
    return this.sanityCheckResults;
  }

  /**
   * Provides a list of the researchers.
   * 
   * @return The researcher list.
   */
  public List<Researcher> getResearchers() {
    return this.researchers;
  }

  /**
   * Loads the researcher data for display.
   * 
   * @return A Resolution indicating to redisplay the display.jsp page.
   */
  public Resolution displayResearchers() {
    myIsern.sortResearchers();
    this.listType = "Researchers";
    this.researchers = myIsern.getResearchers();
    return new ForwardResolution("/display.jsp");
  }

  /**
   * Provides a list of the organizations.
   * 
   * @return The organization list.
   */
  public List<Organization> getOrganizations() {
    return this.organizations;
  }

  /**
   * Loads the organization data for display.
   * 
   * @return A Resolution indicating to redisplay the display.jsp page.
   */
  public Resolution displayOrganizations() {
    myIsern.sortOrganizations();
    this.listType = "Organizations";
    this.organizations = myIsern.getOrganizations();
    return new ForwardResolution("/display.jsp");
  }

  /**
   * Provides a list of the collaborations.
   * 
   * @return The collaboration list.
   */
  public List<Collaboration> getCollaborations() {
    return this.collaborations;
  }

  /**
   * Loads the collaboration data for display.
   * 
   * @return A Resolution indicating to redisplay the display.jsp page.
   */
  public Resolution displayCollaborations() {
    myIsern.sortCollaborations();
    this.listType = "Collaborations";
    this.collaborations = myIsern.getCollaborations();
    return new ForwardResolution("/display.jsp");
  }

  /**
   * Gets a list of warnings from sanity check so that it can be grabbed by the JSP pages.
   * 
   * @return A resolution indicating to redisplay the sanityCheck.jsp page.
   */
  public Resolution getSanityCheckResultsList() {
    this.sanityCheckResults = myIsern.getSanityCheckResultsList();
    return new ForwardResolution("/sanityCheck.jsp");
  }
  
}
